﻿/*----------------------------------------------------------------------------
文件名：tabMange.js
创建人：席吉波
创建日期：2012-10-25
用途：用于管理DHTMLX中tab控件
  ----------------------------------------------------------------------------
*/

(function () {
    function execute() {

        tabManage = function () {
            this._webRequest = null;
            this.tabbar = null;
            this.holder = null;
        }

        tabManage.prototype = {
            init: function (holderID) {
                this.tabbar = new dhtmlXTabBar(holderID, "top");
                this.holder = document.getElementById(holderID);
                //tabbar.setOnActiveFunction(OnTabSetActive);

                this.tabbar.setHrefMode("iframes-on-demand");
                this.tabbar.setSkin("dhx_skyblue");
                this.tabbar.setImagePath("../dhtmlx/tabControl/imgs/");
                this.tabbar.enableTabCloseButton(true);
                this.tabbar.enableAutoReSize(true);

                var menu = window.top.document.getElementById("LeftMenu1");


            },
            newTab: function (id, title, link) {
                //1:先判断该页面是否已经打开,如已打开则直接将已打开的标签置为活动状态               
                var v_tabPageID = "tabPage" + id;
                //*
                //新版的tab控件已经包含此功能

                if (this.tabbar._tabs[v_tabPageID]) {
                    this.tabbar.setTabActive(v_tabPageID);
                    return;
                }
                //*/

                //----------------------------------------------------------------------------
                //2:打开一个新的标签页
                var titleElementLen = this.GetLengthByByte(title) * 10 + 25;
                titleElementLen = Math.max(titleElementLen, 100);

                this.tabbar.addTab(v_tabPageID, title, titleElementLen);
                this.tabbar.setContentHref(v_tabPageID, link);
                this.tabbar.setTabActive(v_tabPageID);
            },

            GetLengthByByte: function (value) {
                var li_len = value.length;
                for (var i = 0; i < value.length - 1; i++) {

                    if (value.charCodeAt(i) > 127)
                        li_len = li_len + 1;
                }
                return li_len;
            },
            holderResize: function (size) {
                $common.setSize(document.body, size);
                $common.setSize(this.holder, { width: size.width - 10, height: size.height - 10 });
            }
        }

        $tabManage = new tabManage();

    } //end exec
    if (!window.$tabManage) {

        execute();
    }
})();
var $tabManage;

